package com.stream;

import java.util.Arrays;
import java.util.IntSummaryStatistics;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;
import java.util.stream.Collectors;

import com.entity.Student;
import com.enums.Gender;
import com.enums.Grade;

public class Demo02 {
	public static void main(String[] args) {
		List<Student> students = Arrays.asList(
				new Student("张三", 10, Gender.MALE, Grade.ONE),
				new Student("张三丰", 8, Gender.MALE, Grade.FOUR),
				new Student("张翠山", 23, Gender.MALE, Grade.ONE),
				new Student("张无极", 12, Gender.MALE, Grade.ONE),
				new Student("殷素素", 43, Gender.FEMALE, Grade.FIVER),
				new Student("赵敏", 23, Gender.FEMALE, Grade.FOUR),
				new Student("周芷若", 12, Gender.FEMALE, Grade.TWO),
				new Student("珠儿", 24, Gender.FEMALE, Grade.SIX),
				new Student("杨不悔", 14, Gender.FEMALE, Grade.THREE),
				new Student("郭靖", 21, Gender.MALE, Grade.FOUR)
				);
		//得到所有学生的年龄
//		List<Integer> ages = students.stream().map(s -> s.getAge()).collect(Collectors.toList());
		//方法引用
		List<Integer> ages = students.stream().map(Student::getAge).collect(Collectors.toList());
//		TreeSet<Integer> ages = students.stream().map(Student::getAge).collect(Collectors.toCollection(TreeSet::new));
		System.out.println("所有学生的年龄："+ages);
		//统计汇总信息
//		IntSummaryStatistics sum = students.stream().collect(Collectors.summarizingInt(Student::getAge));
//		System.out.println("汇总信息:"+sum);
		//分块
		Map<Boolean, List<Student>> genders = students.stream().collect(Collectors.partitioningBy(s -> false));
	}
}
